package com.zunipe.minix;

import com.zunipe.ZunipeTools;
import com.zunipe.until.Util;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket;
import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerRespawnS2CPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ClientPlayNetworkHandler.class)
public class ClientPlayNetworkHandlerMixin
{
    @Inject(method = "onChunkData", at = @At(value = "TAIL"))
    private void onChunkData(ChunkDataS2CPacket packet, CallbackInfo ci)
    {
        if (Util.xrayOn)
        {
            ZunipeTools.os.doMathOnChunk(packet.getX(), packet.getZ());
        }
    }

    @Inject(method = "onGameJoin", at = @At(value = "TAIL"))
    private void onGameJoin(GameJoinS2CPacket packet, CallbackInfo ci)
    {
        reloadOresim();
    }

    @Inject(method = "onPlayerRespawn", at = @At("TAIL"))
    private void respawn(PlayerRespawnS2CPacket packet, CallbackInfo ci)
    {
        reloadOresim();
    }

    private void reloadOresim()
    {
        if (Util.xrayOn)
        {
            ZunipeTools.os.reload();
        }
    }
}
